﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ZBJF.Warranty.Common.Common;
using ZBJF.Warranty.Model;
using ZBJF.Warranty.Model.ViewModel.BaseQueryModel;

namespace ZBJF.Warranty.BLL
{
    public partial class InsuranceProductsInfoCollectCategoryService
    {
        public InsuranceProductsInfoCollectCategory LoadByID(int id)
        {
            return LoadEntities(o => o.ID == id).FirstOrDefault();
        }

        public bool IsExist(string infoCollectCategoryName, int id = 0)
        {
            var expressionWhere = PredicateExtensions.True<InsuranceProductsInfoCollectCategory>();
            expressionWhere = expressionWhere.And(o => o.InfoCollectCategoryName.Equals(infoCollectCategoryName));
            if (id > 0)
            {
                expressionWhere = expressionWhere.And(o => o.ID != id);
            }
            return LoadEntities(expressionWhere).Any();
        }

        public IQueryable<InsuranceProductsInfoCollectCategory> LoadByAll()
        {
            return LoadEntities(o => true);
        }

        public bool Delete(int id)
        {
            var entity = LoadByID(id);
            if (entity != null)
            {
                return DeleteEntities(entity);
            }
            return false;
        }
        public IQueryable<InsuranceProductsInfoCollectCategory> GetPagingList(BaseQueryParams model, out int total)
        {
            var expressionWhere = PredicateExtensions.True<InsuranceProductsInfoCollectCategory>();
            if (!string.IsNullOrEmpty(model.Keyword))
            {
                expressionWhere = expressionWhere.And(o => o.InfoCollectCategoryName.Contains(model.Keyword));
            }
            return LoadPagerEntities<InsuranceProductsInfoCollectCategory>(model.PageIndex, model.iDisplayLength, out total, expressionWhere, model.iSorts);
        }
    }
}
